package com.flower.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.flower.pojo.Admin;
import com.flower.service.IAdminService;


/**
 * 管理员模块  ———— 用户管理
 */

@Controller
public class AdminController {
	
	@Resource(name="adminService")
	private IAdminService iAdminService;
	
	
	/**
	 * 管理员登录
	 */
	@RequestMapping("/adminToLogin.do")
	public String adminToLogin(Admin admin, HttpServletRequest request, Model model){
		Admin adminDB = iAdminService.adminToLogin(admin);
		
		if(adminDB != null){
			request.getSession().setAttribute("ADMIN", adminDB);
			return "redirect:/selectAllProduct.do";
		}else {
			model.addAttribute("msg", "此管理员不存在，请重新输入！");
			return "login";
		}
			
	}
	
	/**
	 * 管理员退出
	 */
	@RequestMapping("/adminToLogout.do")
	public String logout(HttpServletRequest request) {
		// 销毁当前的HttpSession对象
		request.getSession().invalidate();
		// 重定向到default.jsp页面
		return "redirect:/default.jsp";
	}
}
